# 函数自己调用自己 就是递归
# 计算一个数的阶乘
"""
1! = 1
2! = 2*f(1)
3! = 3*f(2)
4! = 4*f(3) = 4*3*f(2) = 4*3*2*f(1) = 4*3*2*1
"""
# 定义一个函数计算
def jiecheng(n):
    res = 1
    for i in range(1,n+1):
        res = res*i
    return res
print(jiecheng(4))
# 改成递归的形式
def jiecheng1(n):
    if n==1:
        return 1
    return n*jiecheng1(n-1)
print(jiecheng1(4))
# 1,1,2,3,5,8,13,21 斐波那契 汉诺塔问题